#include "FunctionParameterBuilder.h"
#include "ScriptCompiler/ASTBuilder/TypeBuilder.h"
#include "ScriptCompiler/AST/ParameterNode.h"
#include "ScriptCompiler/ScriptFileContext.h"

CFunctionParameterBuilder::CFunctionParameterBuilder(std::shared_ptr<CScriptFileContext> InContext)
{
    Context = InContext;
    Result = std::make_shared<CParameterNode>(Context);
}

bool CFunctionParameterBuilder::ReadCurentToken()
{
    auto TypeBuilder = std::make_shared<CTypeBuilder>(Context);
    if (!TypeBuilder->ReadCurentToken())
    {
        return false;
    }
    Result->Type = TypeBuilder->Result;

    auto Token = Context->GetCurrentToken();
    if (Token->Type == EScriptTokenType::Identifier)
    {
        Result->Name = Token;
        Context->CurrentTokenIndex++;
        return true;
    }
    else
    {
        Context->RaiseError(10060,Token,U"Expected parameter name");
        return false;
    }
}
